from rest_framework import serializers
from goods.models import SKU
from orders.models import OrderGoods, OrderInfo

class SKUSerialzier(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ('name','default_image')

# 订单商品序列化器
class OrderGoodsSerializer(serializers.ModelSerializer):
    # 嵌套返回sku商品表，  子嵌套父表返回
    sku = SKUSerialzier()
    class Meta:
        model = OrderGoods
        fields = ('sku','price','count')
# 订单序列化器
class OrderInfoSerializer(serializers.ModelSerializer):
    #嵌套返回订单商品表　　　父嵌套字表返回
    skus = OrderGoodsSerializer(many=True)
    class Meta:
        model = OrderInfo

        fields = "__all__"


